package cn.tj.service.impl;


import cn.tj.entity.Food;
import cn.tj.entity.PageBean;
import cn.tj.mapper.FoodMapper;
import cn.tj.service.FoodService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodServiceImpl implements FoodService {
    @Autowired
    private FoodMapper foodMapper;

    @Override
    public PageBean<Object> foodListByPage(Integer currentPage, Integer pageSize, Double minPrice, Double maxPrice) {
        PageBean<Object> pg = new PageBean<>();
        PageHelper.startPage(currentPage,pageSize);

        List<Food> fList = foodMapper.foodListByPage(currentPage,pageSize,minPrice,maxPrice);
        Page p= (Page) fList;
        pg.setTotal(p.getTotal());
        pg.setItems(p.getResult());

        return pg;
    }

    @Override
    public void editFood(Food food) {
        foodMapper.editFood(food);
    }

    @Override
    public Food getFoodById(Integer id) {
        return  foodMapper.getFoodById(id);
    }

    @Override
    public void deleteFoodById(Integer id) {
        foodMapper.deleteFoodById(id);
    }

    @Override
    public void addFood(Food food) {
        foodMapper.addFood(food);
    }
}
